package com.bosssoft.hr.train.j2se.exception;/*
 * @Auther:hantianbing
 * @Date:2022/12/3
 * @Description:测试应用创建的异常类
 */

import static com.bosssoft.hr.train.j2se.exception.ExceptionCode.ILLEGAL_ACCESS;

/**
 * @ClassName ExceptionDemo
 * @Description 测试应用创建的异常类
 * @Author hantianbing
 * @Date 2022/12/3 10:35
 **/
public class ExceptionDemo {
    /**
     * 模拟try-catch出异常， 抛出BusinessException
     */
    public void method1() throws Exception{
        try{
            int [] nums= new int[10];
            nums[-1] = 1;
        }catch (Exception exception){
            throw new BusinessException(ILLEGAL_ACCESS.getCode(), ILLEGAL_ACCESS.getMsg(), exception.getMessage());
        }
    }

    /**
     * 模拟直接抛出异常
     */
    public void method2(){
        throw new BusinessException();
    }

    /**
     * main方法直接抛出异常
     * @param args
     */
    public static void main(String[] args) {
        ExceptionDemo exceptionDemo = new ExceptionDemo();
        try {
            exceptionDemo.method1();
        } catch (Exception e) {
            e.printStackTrace();
        }
        exceptionDemo.method2();
    }
}
